"""
@author: zwz
@file: 2022-11-04-作业.py
@time: 2022/11/6 0006 19:54:16
"""

# 1、字典底层实现原理
#    哈希表
# 2、圣诞节送礼物题目
    # 互送礼活动
    # 圣诞节到了，公司开展一个互送礼物活动。每个员工系统会随机抽取一位送礼物的对象，送礼对象不能重复。最终每个人都能送出和收到一份礼物。
    # ·定义好公司员工名单
    # ·循环系统会随机抽取一位收礼物的人
    # ·打印最终的送礼和收礼的关系

# import random
# dic = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6}
# print("交换前：", dic)
# giftsout = {}   # 存放交换后的结果
# gifts = [i for i in dic.values()]   # 未分配出的礼物
#
# for x in dic.keys():
#     flag = 0
#     mygift = dic.get(x)
#     if mygift in gifts: # 判断自己的礼物是否在未分配礼物列表中
#         flag = 1
#         gifts.remove(mygift)
#     getgift = random.choice(gifts)  # 随机分配礼物
#     giftsout[x] = getgift
#     gifts.remove(getgift)
#     if flag:
#         gifts.append(mygift)
#
# print("交换后：", giftsout)
#
#
# # 3、随机点名系统， 可以支持请假，抽点过了之后就不用再点了
#
# import random
#
# old_list = ["a", "b", "c", "d", "e", "f", "g", "h"]
# leave = input("请假人员：").split()
# print(f"请假人员：{leave}")
# new_set = set(old_list) - set(leave)
# new_list = list(new_set)
# while True:
#     if len(new_list) == 0:
#         print("全部抽完啦")
#         break
#     num = random.randint(0, len(new_list)-1)
#     a = input("输入q退出，其他继续：")
#     if a == "q":
#         print("退出")
#         break
#     else:
#         print(f"请 {new_list[num]} 回答问题")
#         new_list.pop(num)
#         print()


# 4、写一个三乐购物系统
     #  欢迎提示语
     #1、登录
        #1、查看商品列表（ 种类  ，价钱）
     #2、注册  -- 文件   用户名，密码，账号余额

# import json
# user = {}
# num1 = 1
#
# def shopping():
#     commodity = {"苹果":3, "橘子":5, "梨子":4, "葡萄":6, "芒果":8, "西瓜":15}
#     for key, value in commodity.items():
#         print(key, " ￥", value)
#
#
# def regist():
#     print("注册".center(30,"-"))
#     with open('用户信息.txt', 'a') as file:
#         username = input("请输入用户名：")
#         passwd = input("请输入密码：")
#         money = input("请输入金额：")
#         user[username] = {"passwd": passwd, "money": money}
#         file.write(json.dumps(user))
#         file.write('\n')
#         print("注册成功")
#         print("-"*60)

#
# def login(username, passwd):
#
#     user_message = open("用户信息.txt", 'r')
#     lines = user_message.readlines()
#     message = {}
#     for line in lines:
#         message_1 = eval(line)
#         message = dict(message, **message_1)
#     if username in message and passwd == message[username]['passwd']:
#         print("登录成功")
#         print(f"欢迎光临！你的余额为：{message[username]['money']}")
#         return True
#     elif username in message and passwd != message[username]['passwd']:
#         print("密码错误")
#     else:
#         num3 = input("用户不存在，按 1 注册:")
#         if num3 == "1":
#             regist()
#
# print("欢迎进入三乐购物系统".center(50,"-"))
# while True:
#     print("1、登录".center(50))
#     print("2、注册".center(50))
#     print("3、退出".center(50))
#     num = input("请选择您需要的操作：")
#     if num == "1":
#         print("登录".center(30, "-"))
#         username = input("请输入用户名：")
#         passwd = input("请输入密码：")
#         if login(username, passwd):
#             num2 = input("输入1查看商品列表,其它退出:")
#             if num2 == "1":
#                 print("商品列表".center(30,"-"))
#                 shopping()
#                 break
#             else:
#                 break
#     elif num == "2":
#         regist()
#     elif num == "3":
#         break
#     else:
#         print("请输入 1 或 2 或 3")




# 5、学习go里面的数组、切片、map

#送礼物
import random
user_lst = ["A","B","C","D"]  #送礼物
take = user_lst.copy()        #收礼物
for user in user_lst:
    flag = 0
    if user in take:
        flag = 1
        take.remove(user)
    get = random.choice(take)
    if (len(take) == 2 and flag == 0) and (set(take) & set(user_lst[-2:])):
        get = list(set(user_lst[-2:]) & set(take))[0]
    print(f"{user} -- > {get}")
    take.remove(get)
    if flag == 1:
        take.append(user)
